package com.xjiye_test.payServer.servletGroup.shemmapay;

import com.xiaoleilu.hutool.json.JSONObject;
import com.xiaoleilu.hutool.json.JSONUtil;
import com.xjiye_test.payServer.enums.CheckTest;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class PayParameters extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        resp.setHeader("content-type","text/html;charset=UTF-8");
        req.setCharacterEncoding("UTF-8");
        PrintWriter out = resp.getWriter();
        try{
            String url=req.getParameter("url");
            String privateKey=req.getParameter("pkey");
            String sId=req.getParameter("sid");
            String test=req.getParameter("test");
            String queryIt=req.getParameter("queryIt");
            String[] test_Order=req.getParameterValues("test_Order");
            if(null!=url&&url.length()>0){
                GlobalVariable.payUrl=url;
            }
            if(null!=privateKey&&privateKey.length()>0){
                GlobalVariable.privateKey=privateKey;
            }
            if(null!=sId&&sId.length()>0){
                GlobalVariable.sID=sId;
            }
            if(null!=test&&test.length()>0){
                GlobalVariable.test= CheckTest.valueOf(test);
            }
            if(null!=queryIt&&queryIt.length()>0){
                GlobalVariable.queryIt=Boolean.valueOf(queryIt);
            }
            if(null!=test_Order){
                GlobalVariable.test_Order.clear();
                for(int i=0;i<test_Order.length;i++){
                    GlobalVariable.test_Order.add(test_Order[i]);
                }

            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JSONObject json=new JSONObject();
            json.put("payUrl",GlobalVariable.payUrl);
            json.put("publicKey",GlobalVariable.publicKey);
            json.put("privateKey",GlobalVariable.privateKey);
            json.put("sID",GlobalVariable.sID);
            json.put("signType",GlobalVariable.signType);
            json.put("charset",GlobalVariable.charset);
            json.put("test",GlobalVariable.test.toString());
            json.put("queryIt",GlobalVariable.queryIt);
            json.put("test_Order",GlobalVariable.test_Order);
            out.print(JSONUtil.toJsonStr(json));
        }


    }

}
